package com.ruoyi.StarStudio.Mapper;

import com.ruoyi.StarStudio.Domain.Meteorology;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
@SuppressWarnings("all")
public interface MeteorologyMapper {

    @Select("select * from meteorology")
    public List<Meteorology> findAll();

    List<Meteorology> getList(Meteorology meteorology);

    @Select("select * from meteorology where meteorology_id = #{meteorology_id}")
    public Meteorology getByMeteId(long meteorology_id);

    @Select("select me.* from meteorology me, zone_meteorology zme where me.meteorology_id = zme.meteorology_id and zme.zone_id = #{zoneId} ")
    public List<Meteorology> getAllByZoneId(int zoneId);

//    @Select("select me.* from meteorology me, zone_meteorology zme where me.meteorology_id = zme.meteorology_id and zme.zone_id = #{zoneId} order by meteorology_id desc limit 0,1")
//    public Meteorology getOneByZoneId(int zoneId);

    @Select("select * from meteorology where meteorology_id = #{meteorology_id}")
    public Meteorology getOneByZoneId(long meteorology_id);

    @Select("select max(meteorology_id) from zone_meteorology where zone_id = #{zone_id}")
    public long findMaxMeteIdFromZone_mete(int zoneId);

    @Select("select meteorology_id from meteorology limit 17280")
    public List<Long> findAutoDeleteMeteIds();

    @Insert("insert into meteorology values (null,#{meteorology_temperature}, #{meteorology_humidity}, #{meteorology_co2}, #{meteorology_illuminance}, #{meteorology_rainfall}, #{meteorology_wind_direction}, #{meteorology_wind_speed}, #{meteorology_updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "meteorology_id", keyColumn = "meteorology_id")
    public void add(Meteorology meteorology);

    @Insert("insert into zone_meteorology values(#{zoneId}, #{MeteorologyId})")
    public void addToZone_Meteorology(@Param("zoneId") int zoneId, @Param("MeteorologyId") long MeteorologyId);

    @Update("update meteorology set meteorology_temperature=#{meteorology_temperature},meteorology_humidity=#{meteorology_humidity},meteorology_co2=#{meteorology_co2},meteorology_illuminance=#{meteorology_illuminance}, meteorology_rainfall = #{meteorology_rainfall}, meteorology_wind_direction = #{meteorology_wind_direction}, meteorology_wind_speed = #{meteorology_wind_speed}, meteorology_updateTime=#{meteorology_updateTime} where meteorology_id = #{meteorology_id}")
    public void update(Meteorology meteorology);

    @Delete("delete from meteorology where meteorology_id = #{meteorologyId}")
    public void delete(long meteorologyId);

    @Delete("delete from zone_meteorology where meteorology_id = #{meteorologyId}")
    public void deleteFromZone_Meteorology(long meteorologyId);

}
